package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"strconv"
	"strings"
)

func GetTotalMemory() uint64 {
	contents, err := ioutil.ReadFile("/proc/meminfo")
	if err != nil {
		log.Fatal(err)
		return 0
	}

	lines := strings.Split(string(contents), "\n")
	memCap := uint64(0)
	for _, line := range lines {
		fields := strings.Fields(line)
		fmt.Println(fields)
		if fields[0] == "MemTotal:" {
			size, err := strconv.ParseUint(fields[1], 10, 64)
			if err != nil {
				log.Fatal(err)
			}
			memCap = size
			break
		}
	}

	return memCap
}

func main() {
	memSize := GetTotalMemory()

	fmt.Printf("mem cap: %v\n", memSize)
}
